'''
author:陈杨涛
intruduction：伦理审查审批模块接口测试
'''
import json
import unittest
import requests
from jsonpath import jsonpath
from parameterized import parameterized

from utils.reader import Reader
from utils.session import Session


class AniamlEthic(unittest.TestCase):
    """
    author:陈杨涛
    intruduction：动物实验伦理审批测试类
    """
    s = None
    session_token = None
    @classmethod
    def setUpClass(cls) -> None:
        cls.s = Session.get_session()
        cls.session_token = Session.get_header()
    @classmethod
    def tearDownClass(cls) -> None:
        cls.s.close()

    #使用Reader传入用例数据
    @parameterized.expand(Reader.read_excel('animal.xlsx',min_row=2, max_row=9, min_col=9, max_col=10))

    def test_ethic(self, param ,expected):
        """
        伦理审查查询测试方法
        """
        url = 'http://120.53.243.26:8009/api/ethicsReview/search/findPage'
        #接收过来的提交数据格式是字符串格式，转成python字典格式
        data = json.loads(param)
        resp = self.s.post(url, json=data, headers=self.session_token)

        #将相应正文转换成字典类型判断content字段是否为空
        text_result = json.loads(resp.text)
        text_result1 = text_result['resData']['content']
        judge = len(text_result1)
        if expected == 'content为空':
            self.assertEqual(0, judge)
        else:
            self.assertNotEqual(0,judge)
        self.assertEqual(200, resp.status_code)